#!/sbin/openrc-run

name="TACACS+NG"
description="TACACS+ authentication daemon"

extra_started_commands="reload"
description_reload="Reload configuration file"

: ${command_user="tacacs"}
: ${cfgfile:="/etc/tac_plus-ng.cfg"}

command="/usr/sbin/tac_plus-ng"
command_args="-f
	${child_id:+-i $child_id}
	${spawnd_id:+-I $spawnd_id}
	$command_args
	$cfgfile
	"
command_background="yes"
pidfile="/run/$RC_SVCNAME.pid"

# (This is supported since OpenRC 0.45)
capabilities="^cap_net_raw,^cap_net_bind_service"

required_files="$cfgfile"

depend() {
	need net
}

start_pre() {
	$command -P "$cfgfile"
}

checkconfig() {
	ebegin "Checking $name configuration"
	start_pre
	eend $?
}

reload() {
	ebegin "Reloading $name configuration"

	if [ "$supervisor" ]; then
		$supervisor "$RC_SVCNAME" --signal HUP
	else
		start-stop-daemon --pidfile "$pidfile" --signal HUP
	fi
	eend $?
}
